/*******************************************************************************
 * The MOSES project, model based software engineering of networked embedded systems.
 * 
 * Copyright (C) 2010-2013, University of Applied Sciences Wildau,
 * Telematics Research Group, http://www.tm.th-wildau.de/research-group
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses>.
 * 
 * Contributors:
 *     University of Applied Sciences Wildau - initial API and implementation
 * 
 * If you are interested in a commercial license please contact us via 
 * e-mail: ralf.vandenhouten@th-wildau.de.
 ******************************************************************************/
package de.thwildau.tm.moses.examples.nmea.data;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import de.thwildau.tm.moses.abnf.io.AbnfCoder;

/**
 * The GP-GLL (Geographic Position - Latitude/Longitude) class of NMEA.
 * <p>
 * The structure is:
 * 
 * <pre>
 *        1       2 3        4 5         6 7
 *        |       | |        | |         | |
 * $--GLL,llll.ll,a,yyyyy.yy,a,hhmmss.ss,A*hh<CR><LF>
 * 
 *  Field Number: 
 *   1) Latitude
 *   2) N or S (North or South)
 *   3) Longitude
 *   4) E or W (East or West)
 *   5) Universal Time Coordinated (UTC)
 *   6) Status A - Data Valid, V - Data Invalid
 *   7) Checksum
 * </pre>
 * 
 * </p>
 * 
 * @author Thomas Kistel
 * @version $Revision: 764 $
 */
public class GpGll extends Nmea {

    private Float latitude;
    private LatitudeOrientation latitudeOrientation;
    private Float longitude;
    private LongitudeOrientation longitudeOrientation;
    private Float utcTime;
    private GpGllStatus status;


    public Float getLatitude() {
        return latitude;
    }

    public void setLatitude(Float latitude) {
        this.latitude = latitude;
    }

    public LatitudeOrientation getLatitudeOrientation() {
        return latitudeOrientation;
    }

    public void setLatitudeOrientation(LatitudeOrientation latitudeOrientation) {
        this.latitudeOrientation = latitudeOrientation;
    }

    public Float getLongitude() {
        return longitude;
    }

    public void setLongitude(Float longitude) {
        this.longitude = longitude;
    }

    public LongitudeOrientation getLongitudeOrientation() {
        return longitudeOrientation;
    }

    public void setLongitudeOrientation(LongitudeOrientation longitudeOrientation) {
        this.longitudeOrientation = longitudeOrientation;
    }

    public Float getUtcTime() {
        return utcTime;
    }

    public void setUtcTime(Float utcTime) {
        this.utcTime = utcTime;
    }

    public GpGllStatus getStatus() {
        return status;
    }

    public void setStatus(GpGllStatus status) {
        this.status = status;
    }

    @Override
    public void read(DataInput in) throws IOException {
        this.latitude = AbnfCoder.decodeUntil(in, ",", Float.class);
        this.latitudeOrientation = AbnfCoder.decode(in, LatitudeOrientation.values());
        AbnfCoder.checkDecode(in, ",");
        this.longitude = AbnfCoder.decodeUntil(in, ",", Float.class);
        this.longitudeOrientation = AbnfCoder.decode(in, LongitudeOrientation.values());
        AbnfCoder.checkDecode(in, ",");
        this.utcTime = AbnfCoder.decodeUntil(in, ",", Float.class);
        this.status = AbnfCoder.decode(in, GpGllStatus.values());
        AbnfCoder.checkDecode(in, "*");
        String checksum = AbnfCoder.decode(in, 2);
        this.checksum = Integer.valueOf(checksum, 16);
    }

    @Override
    public void write(DataOutput out) throws IOException {
        throw new UnsupportedOperationException("Not implemented.");
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("GpGll");
        builder.append(",").append(latitude);
        builder.append(",").append(latitudeOrientation);
        builder.append(",").append(longitude);
        builder.append(",").append(longitudeOrientation);
        builder.append(",").append(utcTime);
        builder.append(",").append(status);
        return builder.toString();
    }
}
